package com.app.qbake.module.msg;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.app.qbake.R;
import com.app.qbake.module.login.event.LoginSuccessEvent;
import com.netease.nim.uikit.business.recent.RecentContactsFragment;
import com.wind.view.TitleBar;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;

/**
 * Created by wind on 2018/10/30.
 */

public class MsgFragment extends Fragment {

    RecentContactsFragment fragment;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_msg,container,false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        EventBus.getDefault().register(this);
        TitleBar titleBar=view.findViewById(R.id.title_bar);
        titleBar.setTitle("消息");
        titleBar.setTextColor(Color.parseColor("#333333"));
        titleBar.setLineColor(getResources().getColor(com.wind.base.R.color.colordbdbdb));

        fragment= (RecentContactsFragment) getChildFragmentManager().findFragmentByTag("fragment_recent");
    }



    @Subscribe
    public void onLoginSuccessEvent(LoginSuccessEvent event){
        if (fragment!=null) {
            fragment.requestMessages(true);
        }
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        EventBus.getDefault().unregister(this);
    }
}
